package com.msstudio;

// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 

import com.msstudio.utils.PkgTools;
import java.io.DataInputStream;
import java.io.InputStream;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Icons
    implements Runnable
{//������Ҫ��ͼ����в�����

    public static final int C_SystemHeadBmp_Num = 85;//������ϵͳͼ������Ϊ85��

    private final int C_BMP_Size = 112;//ϵͳͼ��ߴ�Ϊ112�ֽڣ�
    private int bmpLoaded;//��ųɹ����ص�ͼ����
    private Thread thread;//�̶߳���
    private int palette[] = {
        0, 0x800000, 32768, 0x808000, 128, 0x800080, 32896, 0x808080, 0xc0c0c0, 0xff0000, 
        65280, 0xffff00, 255, 0xff00ff, 65535, 0xffffff
    };//����һ��16ɫ����ɫ�壻
    private Image iconImg[];//��ųɹ����ص�ͼ�꣬һ��85����
    Image imgHead[];//������ߡ����ߡ��뿪���ͼ�ꣻ
    Image imgSys[];//���ϵͳ��Ϣ���뿪���������ͼ�ꣻ

    public Icons()
    {//���캯���һЩ��������ʵʼ����
        bmpLoaded = 0;
        thread = null;
        imgHead = new Image[4];
        imgSys = new Image[4];
        iconImg = new Image[85];
    }

    public void init()
    {//��ʼ����̣�
        loadScreenBmp();
        loadSysBmp();
        thread = new Thread(this);
        thread.setPriority(1);
        thread.start();
    }

    public void run()
    {//���нӿں���װ��/bmp.bin�ļ������ļ��д����85��ͼ�꣬ÿ��ͼ��ռ��112�ֽڣ�
        byte abyte0[] = new byte[112];
        try
        {
            InputStream inputstream = getClass().getResourceAsStream("/bmp.bin");
            DataInputStream datainputstream = new DataInputStream(inputstream);
            for(int i = 0; i < 85; i++)
            {
                datainputstream.read(abyte0, 0, 112);
                Image image = Image.createImage(14, 14);
                Graphics g = image.getGraphics();
                drawIcon(abyte0, g, 0, 0, palette);
                iconImg[i] = image;
                bmpLoaded++;//�ɹ����ص�ͼ����
            }

        }
        catch(Exception exception) { }
    }

    private void drawIcon(byte abyte0[], Graphics g, int i, int j, int ai[])
    {//��i,j������һ��ICON��Graphics������ȥ����ICONΪ14*14��16ɫ��ͼ�񣬼�ÿ��
     //����ɫֵΪ4λ��һ�ֽڿɴ�����������ɫֵ����˹���98�ֽڵ��ڴ������һ��ICON��
     //��ICON�Ǵӵ����������ҿ�ʼ����
     //����˵����byte abyte0[]��ͼ�����
     //          Graphics g, �������
     //          int i, int j, ���
     //          int ai[],����ɫ�壻
        int i1 = 0;
        for(int k = j + 13; k >= j; k--)
        {
            for(int l = i; l < i + 14;)
            {
                int j1 = (abyte0[i1] & 0xf0) >> 4;
                if(j1 < 15)
                {
                    g.setColor(ai[j1]);
                    g.drawLine(l, k, l, k);
                }
                l++;
                j1 = abyte0[i1] & 0xf;
                if(j1 < 15)
                {
                    g.setColor(ai[j1]);
                    g.drawLine(l, k, l, k);
                }
                l++;
                i1++;
            }

            i1++;
        }

    }

    private void loadScreenBmp()
    {//װ�����ߡ����ߡ��뿪ͼ��(1-1.png��1-2.png��1-3.png)��imgHead������ȥ��
        Object obj = null;
        for(int i = 0; i < 3; i++)
        {
            String s = "/1-" + (i + 1) + ".png";
            imgHead[i] = PkgTools.createImage(s);
        }

    }

    private void loadSysBmp()
    {//װ��ϵͳ��Ϣ���뿪������ͼ��(2sys.png��3sys.png��4sys.png)��imgSys������ȥ��
        Object obj = null;
        for(int i = 1; i < 4; i++)
        {
            String s = "/" + (i + 1) + "sys.png";
            imgSys[i] = PkgTools.createImage(s);
        }

        imgSys[0] = imgHead[0];
    }

    public Image getSysImage(int i)
    {//ȡ��ϵͳͼ��
        return imgSys[i];
    }

    public Image getHeadImage(int i, int j)
    {//���״̬ȡ��ͼ����
        int k = i / 3;
        switch(j)
        {
        case 20: // '\024'
        case 40: // '('
            return imgHead[1];

        case 30: // '\036'
            return imgHead[2];

        default:
            return imgHead[1];

        case 10: // '\n'
            break;
        }
        if(k < bmpLoaded)
            return iconImg[k];
        if(j == 10)
            return imgHead[0];
        else
            return imgHead[1];
    }
}
